﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.Dto.ProSorce;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.culture
{
    public class CultureRevealHander : IRequestHandler<CultureRevealCommond, Rulst>
    {

        private readonly IbaseRpository<Goods> _Goods;
        private readonly IbaseRpository<ProductionBasicMess> _ProductionBaseicMess;
        private readonly IbaseRpository<ProductionPutImages> _ProductionPutImages;

        public CultureRevealHander(IbaseRpository<Goods> goods, IbaseRpository<ProductionBasicMess> productionBaseicMess, IbaseRpository<ProductionPutImages> _ProductionPutImages)
        {
            _Goods = goods;
            _ProductionBaseicMess = productionBaseicMess;
            this._ProductionPutImages = _ProductionPutImages;
        }

        public async Task<Rulst> Handle(CultureRevealCommond request, CancellationToken cancellationToken)
        {

            var query = new Rulst() { Code = (int)Reult.success };





            var list = (from a in _Goods.Query()
                        join b in _ProductionBaseicMess.Query() on a.Goodsid equals b.Goodsid
                        where b.ProDuctionBasicid == request.ProDuctionBasicid
                        select new CultureRevealDto
                        {
                            expirationtime = b.expirationtime,
                            GoodsName = a.GoodsName,
                            ProductionBath = b.ProductionBath,
                            ProDuctionenterprise = b.ProDuctionenterprise,
                            ProDuctionImages = b.ProDuctionImages,
                            ProDuctionNum = b.ProDuctionNum,
                            cultureRevealGETiamges = new List<CultureRevealGETiamges>()


                        }).FirstOrDefault();


            list.cultureRevealGETiamges = _ProductionPutImages.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid && x.Stypeid == Typenum.产品检验报告).Select(x => new CultureRevealGETiamges
            {

                PutImages = x.PutImages,
                Productionimagesid = x.Putid,

            }).ToList();


            if (list != null)
            {
                query.data = list;

                query.MSG = "消息成功";
            }


            return query;


        }
    }
}
